{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ce2486bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "冯潇宇\n",
    "320200930851\n",
    "一班\n",
    "\"\"\"\n",
    "import csv\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cdfdf354",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87442\n"
     ]
    }
   ],
   "source": [
    "with open('.\\gaze.csv', 'r') as f:\n",
    "    reader = csv.DictReader(f)\n",
    "    valid = []\n",
    "    for i in reader:\n",
    "        if float(i['confidence']) >= 0.9:\n",
    "            valid.append(row)\n",
    "    print(len(valid))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "03ac241c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120036\n"
     ]
    }
   ],
   "source": [
    "def sigma(data):\n",
    "    num1 = 0\n",
    "    num2 = 0\n",
    "    lenth = len(data)\n",
    "    for i in data:\n",
    "        num1 += i\n",
    "    avg = num1 / lenth\n",
    "    for i in data:\n",
    "        num2 += (i-avg) ** 2\n",
    "    sigma = (num2/lenth) ** 0.5\n",
    "    num3 = avg - 3 * sigma\n",
    "    num4 = avg + 3 * sigma\n",
    "    return(num3,num4,sigma)\n",
    "\n",
    "with open('.\\gaze.csv', 'r') as f:\n",
    "    reader = csv.DictReader(f)\n",
    "    x = []\n",
    "    y = []\n",
    "    ans = 0\n",
    "    for row in reader:\n",
    "        x.append(float(row['norm_pos_x']))\n",
    "        y.append(float(row['norm_pos_y']))\n",
    "\n",
    "    sigma1 = sigma(x)\n",
    "    sigma2 = sigma(y)\n",
    "\n",
    "    for i in range(len(a1)):\n",
    "        if (x[i] > sigma1[0] and x[i] < sigma1[1]) and (y[i] > sigma2[0] and y[i] < sigma2[1]):\n",
    "            ans += 1\n",
    "    print(ans)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "56a9c3b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-02T00:29:10.776780+0000\n",
      "1970-01-02T00:29:10.776790+0000\n",
      "1970-01-02T00:29:10.779710+0000\n",
      "1970-01-02T00:29:10.779760+0000\n",
      "1970-01-02T00:29:10.787490+0000\n",
      "1970-01-02T00:29:10.787580+0000\n",
      "1970-01-02T00:29:10.789480+0000\n",
      "1970-01-02T00:29:10.793580+0000\n",
      "1970-01-02T00:29:10.795680+0000\n",
      "1970-01-02T00:29:10.798410+0000\n",
      "1970-01-02T00:29:10.801140+0000\n"
     ]
    }
   ],
   "source": [
    "with open('.\\gaze.csv', 'r') as f:\n",
    "    reader = csv.DictReader(f)\n",
    "    a = 0\n",
    "    for row in reader:\n",
    "        x = float(row['gaze_timestamp'])\n",
    "        time = datetime.datetime.utcfromtimestamp(x)\n",
    "        time = time.strftime('%Y-%m-%dT%H:%M:%S.%f+0000')\n",
    "        a += 1       \n",
    "        print(time)\n",
    "        if a > 10:\n",
    "            break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "31a20239",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "428\n"
     ]
    }
   ],
   "source": [
    "with open('.\\gaze.csv', 'r') as f:\n",
    "    reader = csv.DictReader(f)\n",
    "    x = []\n",
    "    a = 0\n",
    "    for row in reader:\n",
    "        x.append(float(row['gaze_timestamp']))\n",
    "        a += 1\n",
    "    time = (x[-1] - x[0])\n",
    "    ans = a / int(time)\n",
    "    print(int(ans))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "7efd3919",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['88150.77678', '0', '0.828005946', '0.531432713', '0.397509462', '88150.77678-0', '28.3697529', '52.03313456', '705.1211159', '20', '15', '-20', '0.011526769', '0.05100179', '0.99863204', '', '', '', '', '', '']\n",
      "['88150.78749', '1', '0.50259488', '0.340108912', '0.142989495', '88150.787485-1', '-139.4048601', '175.0883214', '681.1514528', '-39.93492801', '14.99791945', '-20.07528253', '-0.136989337', '0.22047545', '0.965724856', '', '', '', '', '', '']\n",
      "['88150.79358', '1', '0.625134035', '0.495992731', '0.399020684', '88150.79569-0 88150.79147699999-1', '1.533099949', '-21.7308616', '-298.8904405', '20', '15', '-20', '0.06514516', '0.027374146', '0.997500258', '-39.93492801', '14.99791945', '-20.07528253', '-0.145087255', '0.230744394', '0.962136536']\n",
      "['88150.80114', '1', '0.708476074', '0.495145416', '0.408338473', '88150.801157-0 88150.801123-1', '1.782443785', '-18.93099285', '-286.8493091', '20', '15', '-20', '0.067222081', '0.026625008', '0.997382725', '-39.93492801', '14.99791945', '-20.07528253', '-0.152522642', '0.222659333', '0.962891305']\n",
      "['88150.81287', '2', '0.856340761', '0.49480892', '0.402125481', '88150.809749-0 88150.815997-1', '1.914320557', '-20.30247952', '-288.1024451', '20', '15', '-20', '0.066337739', '0.023839908', '0.997512387', '-39.93492801', '14.99791945', '-20.07528253', '-0.152093872', '0.233980362', '0.960271131']\n",
      "['88150.82182', '2', '0.861112802', '0.493452992', '0.399838536', '88150.823534-0 88150.820104-1', '2.451823208', '-21.09937029', '-292.5744058', '20', '15', '-20', '0.063319819', '0.025199444', '0.997675092', '-39.93492801', '14.99791945', '-20.07528253', '-0.151527396', '0.234143013', '0.960321039']\n",
      "['88150.83164', '2', '0.792455434', '0.493562742', '0.398006681', '88150.831679-0 88150.83159799999-1', '2.429747589', '-21.6548145', '-294.8833474', '20', '15', '-20', '0.062870061', '0.027410668', '0.997645233', '-39.93492801', '14.99791945', '-20.07528253', '-0.150210472', '0.233746547', '0.960624467']\n",
      "['88150.84223', '2', '0.861800715', '0.492773876', '0.39944442', '88150.841019-0 88150.84344899999-1', '2.740186326', '-21.4488181', '-296.2543203', '20', '15', '-20', '0.061462252', '0.024974843', '0.997796898', '-39.93492801', '14.99791945', '-20.07528253', '-0.150562124', '0.233448037', '0.960642004']\n",
      "['88150.85154', '3', '0.814634635', '0.492873494', '0.398929824', '88150.85153599999-0 88150.851534-1', '2.713785009', '-21.64932512', '-297.5012828', '20', '15', '-20', '0.061283019', '0.025668513', '0.997790318', '-39.93492801', '14.99791945', '-20.07528253', '-0.149816675', '0.233035966', '0.960858576']\n",
      "['88150.86204', '3', '0.865288341', '0.492818966', '0.39798609', '88150.864506-0 88150.85956499999-1', '2.747911798', '-21.95824899', '-298.9549967', '20', '15', '-20', '0.060837375', '0.025457537', '0.997822994', '-39.93492801', '14.99791945', '-20.07528253', '-0.149151859', '0.234053214', '0.960714742']\n",
      "['88150.87173', '3', '0.779777956', '0.49225284', '0.398469793', '88150.87172699999-0 88150.871726-1', '2.969823973', '-21.89303602', '-299.48717', '20', '15', '-20', '0.05994958', '0.025324603', '0.997880109', '-39.93492801', '14.99791945', '-20.07528253', '-0.149645418', '0.233257839', '0.960831426']\n",
      "['88150.88174', '4', '0.945000471', '0.492317895', '0.398975706', '88150.879586-0 88150.88389-1', '2.944875662', '-21.78387202', '-299.486159', '20', '15', '-20', '0.060040362', '0.024936294', '0.99788443', '-39.93492801', '14.99791945', '-20.07528253', '-0.149568256', '0.232895646', '0.960931296']\n",
      "['88150.89', '4', '0.825606805', '0.492182499', '0.397400267', '88150.888291-0 88150.891702-1', '3.013482745', '-22.24690193', '-301.1555089', '20', '15', '-20', '0.05943898', '0.025782407', '0.99789893', '-39.93492801', '14.99791945', '-20.07528253', '-0.148915824', '0.233733232', '0.960829253']\n",
      "['88150.90154', '4', '0.821102522', '0.491613459', '0.397494745', '88150.89951199999-0 88150.90357499999-1', '3.240232461', '-22.27727032', '-301.8445575', '20', '15', '-20', '0.058503551', '0.025052783', '0.997972792', '-39.93492801', '14.99791945', '-20.07528253', '-0.149322254', '0.23403122', '0.960693631']\n",
      "['88150.91139', '5', '0.929132762', '0.491363104', '0.398148615', '88150.91139099999-0 88150.91137999999-1', '3.339172826', '-22.14984503', '-302.0447272', '20', '15', '-20', '0.058120769', '0.024277222', '0.998014325', '-39.93492801', '14.99791945', '-20.07528253', '-0.149559391', '0.233747564', '0.960725801']\n",
      "['88150.92348', '5', '0.856588177', '0.491535186', '0.396165551', '88150.91942399999-0 88150.92752699999-1', '3.288905094', '-22.69331226', '-303.5455907', '20', '15', '-20', '0.057982053', '0.026013439', '0.997978648', '-39.93492801', '14.99791945', '-20.07528253', '-0.148601659', '0.234394242', '0.960716861']\n",
      "['88150.93188', '5', '0.998202317', '0.491173047', '0.396200664', '88150.93622799999-0 88150.92752699999-1', '3.440890035', '-22.76025241', '-304.5439691', '20', '15', '-20', '0.057255736', '0.025567573', '0.998032104', '-39.93492801', '14.99791945', '-20.07528253', '-0.148601659', '0.234394242', '0.960716861']\n",
      "['88150.94089', '5', '0.739420778', '0.49142312', '0.397075337', '88150.940894-0 88150.94089099999-1', '3.33488529', '-22.51093612', '-303.7677084', '20', '15', '-20', '0.057780027', '0.024714738', '0.998023372', '-39.93492801', '14.99791945', '-20.07528253', '-0.148647506', '0.23424002', '0.960747382']\n",
      "['88150.9515', '6', '0.803616379', '0.491446201', '0.396408371', '88150.947523-0 88150.95548399999-1', '3.321166939', '-22.62449331', '-303.3344266', '20', '15', '-20', '0.057914416', '0.025849307', '0.99798684', '-39.93492801', '14.99791945', '-20.07528253', '-0.148820867', '0.234277045', '0.960711515']\n",
      "['88150.96149', '6', '0.839118919', '0.490797009', '0.397549338', '88150.963521-0 88150.95945699999-1', '3.571551466', '-22.36481116', '-303.1921606', '20', '15', '-20', '0.057074997', '0.023794625', '0.998086299', '-39.93492801', '14.99791945', '-20.07528253', '-0.149732915', '0.234648548', '0.960479106']\n"
     ]
    }
   ],
   "source": [
    "with open('.\\gaze.csv', 'r') as f:\n",
    "    reader = csv.DictReader(f)\n",
    "    a = 8815077\n",
    "    for row in reader:\n",
    "        b = float(row['gaze_timestamp'])\n",
    "        c = int(b*100)\n",
    "        if c == a:\n",
    "            print(list(row.values()))\n",
    "            a += 1\n",
    "        if a == 8815097:\n",
    "            break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f0150a6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
